package common

import (
	"encoding/json"
	"github.com/spf13/viper"
	"io/ioutil"
)

type LogConf struct {
	Path string
	Level string
}
type Config struct {
	Viper *viper.Viper
	Log   LogConf
	Other map[string]interface{}
}

var (
	GConfig *Config
)

func InitConfig(filename string) (err error) {
	var (
		bytes []byte
	)
	if bytes, err = ioutil.ReadFile(filename); err != nil {
		return
	}
	GConfig = &Config{Viper: viper.New()}
	if err = json.Unmarshal(bytes, GConfig); err != nil {
		return
	}
	for k, v := range GConfig.Other {
		GConfig.Viper.Set(k, v)
	}
	return

}
